package it.polimi.travelDreamEJB.web.beans;

import java.util.List;

import it.polimi.travelDreamEJB.basicproductmanagement.BasicProductMgr;
import it.polimi.travelDreamEJB.basicproductmanagement.dto.ExcursionDTO;
import it.polimi.travelDreamEJB.basicproductmanagement.dto.HotelDTO;
import it.polimi.travelDreamEJB.basicproductmanagement.dto.SearchExcursionDTO;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;

import org.primefaces.event.RowEditEvent;

@ManagedBean(name="excursionBean")
@ViewScoped
public class ExcursionBean {

	@EJB
	private BasicProductMgr bpm;
	
	private ExcursionDTO excursion;
	
	private SearchExcursionDTO searchExcursion;
	
	private List<ExcursionDTO> excursionList;
	
	public ExcursionBean() {
		searchExcursion = new SearchExcursionDTO();
		excursion = new ExcursionDTO();
	}
	
	public ExcursionDTO getExcursion() {
		return excursion;
	}
	
	public void setExcursion(ExcursionDTO excursion) {
		this.excursion = excursion;
	}
	
	public SearchExcursionDTO getSearchExcursion() {
		return searchExcursion;
	}
	
	public void setSearchExcursion(SearchExcursionDTO searchExcursion) {
		this.searchExcursion = searchExcursion;
	}
	
	public List<ExcursionDTO> getExcursionList() {
		return excursionList;
	}
	
	public void setExcursionList(List<ExcursionDTO> excursionList) {
		this.excursionList = excursionList;
	}
	
	public String save() {
		bpm.save_excursion(excursion);
		return "basic?faces-redirect=true";
	}
	
	public void find() {

		excursionList = bpm.findExcursion(searchExcursion);

	}
	
	public void delete(RowEditEvent event) {

		excursion = ((ExcursionDTO) event.getObject());
		bpm.delete_excursion(excursion);
		excursionList.remove(excursion);

	}

	public void update(RowEditEvent event) {

		bpm.update_excursion(((ExcursionDTO) event.getObject()));

	}
	
}